﻿using Coldairarrow.Business.Base;
using Coldairarrow.Entity.Base;
using Coldairarrow.Entity.DTO;
using Coldairarrow.Util;
using Coldairarrow.Util.ClassLibrary;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using System.Collections.Generic;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.Base
{
    [Route("/Base/[controller]/[action]")]
    public class Base_UnitItemsController : BaseApiController
    {
        #region DI
        private readonly RedisOptions _redisOptions; //1.声明

        public Base_UnitItemsController(IBase_UnitItemsBusiness base_UnitItemsBus, IOptions<RedisOptions> redisOptions)
        {
            _base_UnitItemsBus = base_UnitItemsBus;
            _redisOptions = redisOptions.Value;//3.赋值

        }

        IBase_UnitItemsBusiness _base_UnitItemsBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<Base_UnitItems>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _base_UnitItemsBus.GetDataListAsync(input);
        }

        [HttpPost]
        public async Task<Base_UnitItems> GetTheData(IdInputDTO input)
        {
            return await _base_UnitItemsBus.GetTheDataAsync(input.id);
        }

        [HttpPost]
        public async Task<List<Base_UnitItemsDTO>> GetDataListByArea(string GroupId)
        {
            var res = await _base_UnitItemsBus.GetDataListAsyncs(GroupId);
            return res;
        }

        [HttpPost]
        public async Task<List<Base_UnitItemsDTO>> GetDataListTypeByArea(string GroupId)
        {
            var res = await _base_UnitItemsBus.GetDataListGroupAsync(GroupId);
            return res;
        }

        [HttpPost]
        public async Task<PageResult<Base_UnitItems>> GetDataGroupList(PageInput<ConditionDTO> input,string GroupId)
        {
            return await _base_UnitItemsBus.GetDataGroupListAsync(input,GroupId);
        }


        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(Base_UnitItems data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _base_UnitItemsBus.AddDataAsync(data, _redisOptions);
            }
            else
            {
                await _base_UnitItemsBus.UpdateDataAsync(data, _redisOptions);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _base_UnitItemsBus.DeleteDataAsync(ids);
        }

        #endregion
    }
}